

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>小说列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
      .layui-card span[lay-separator] {
        margin: 0 10px;
        color: #999;
        font-weight: bold;
      }
      body .layui-layer-demo .layui-layer-content {
        overflow: visible;
      }
    </style>
  </head>

<body>
  <div class="layui-fluid" id="LAY-component-grid-stack">
    <div class="layui-card">

      <div class="layui-card-header">
           App审核书籍
      </div>

        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
          <div class="layui-form-item">

            <div class="layui-inline">
              <button class="layui-btn layuiadmin-btn-admin layui-btn-primary" type="button" onclick="history.back();">
                <i class="layui-icon layui-icon-return layuiadmin-button-btn"></i>返回
              </button>
            </div>

            <div class="layui-inline">
              <input type="text" name="novel_id" placeholder="小说ID" autocomplete="off" class="layui-input" value="{$Request.param.id}">
            </div>

            <div class="layui-inline">
              <select name="quick_id"  lay-search>
                <option value="">请选择</option>
                {foreach $qas as $k => $v}
                <option value="{$v.id}">{$v.name}</option>
                {/foreach}
              </select>
            </div>

          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
          </div>
        </div>
      <div class="layui-card-body">
        <script type="text/html" id="toolbarDemo">
          <div class="layui-btn-container">
            <button class="layui-btn layui-btn-primary layui-border-red layui-btn-sm" lay-event="del">批量删除</button>
            <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
          </div>
        </script>

        <script type="text/html" id="classTpl">
          {{#  if(d.novel.freq && d.novel.novel_class){ }}
          {{d.novel.freq.name}}<span lay-separator="">·</span>{{d.novel.novel_class.name}}
          {{#  } }}
        </script>

        <table id="LAY-user-back-role" lay-filter="LAY-user-back-role"></table>
        <script type="text/html" id="table-useradmin-admin">
          <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete" ></i></a>
        </script>
      </div>
    </div>

  </div>

  <div class="man-show" style="display: none;">
    <form class="layui-form layui-form-pane" style="padding: 10px;" action="">

      <div class="layui-form-item">
        <label class="layui-form-label">App</label>
        <div class="layui-input-block">
          <select name="quick_id" id="quick_id" lay-search>
            <option value=""></option>
            {foreach $qas as $k => $v}
            <option value="{$v.id}">{$v.name}</option>
            {/foreach}
          </select>
        </div>
      </div>

      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">小说ID
          <button type="button" class="layui-btn layui-btn-xs layui-btn-primary" style="float: right;" onclick="random();">随机赋值</button>
        </label>
        <div class="layui-input-block">
          <textarea id="novel_ids" placeholder="请输入id，并用半角逗号分隔，如：1,2,3,4,5,6" class="layui-textarea"></textarea>
        </div>
        <div class="layui-form-mid layui-word-aux">随机赋值：随机拿20本未使用过的C级书ID，显示在上方输入框</div>
      </div>


    </form>
  </div>

  <script src="/static/layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index','table'], function () {
      var $ = layui.$
              ,admin = layui.admin
              ,table = layui.table
              ,form = layui.form;

      //监听搜索
      form.on('submit(LAY-user-back-search)', function(data){
        var field = data.field;

        //执行重载
        table.reload('LAY-user-back-role', {
          where: field
        });
      });

      table.render({
        elem: '#LAY-user-back-role'
        , url: '/quick_app/examineNovels' //模拟接口
        , response: {
          statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
        }
        , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        , defaultToolbar: false
        , page: true //开启分页
        , limit: 20
        , cols: [[
          {type: 'checkbox'}
          ,{field: 'quick_app', width: 250, title: 'App',templet:function (d) {
                return d.quick_app.name;
            }}
          ,{field: 'novel_id', width: 150, title: '小说ID'}
          , {field: 'novel.title', title: '小说名', minWidth: 200,templet:function (d) {
                return d.novel.title;
            }}
          , {
            field: 'scale', title: '评级', align: 'center', templet: function (d) {
              if (d.novel.scale === 'S') {
                return '<span style="color: #FF5722;">S级</span>'
              } else if (d.novel.scale === 'A') {
                return '<span style="color: #FFB800;">A级</span>'
              } else if (d.novel.scale === 'B') {
                return '<span style="color: #01AAED;">B级</span>'
              } else if (d.novel.scale === 'C') {
                return '<span style="color: #5FB878;">C级</span>'
              } else {
                return '';
              }
            }
          }
          , {field: 'class', title: '频道<span lay-separator="">·</span>分类', templet: '#classTpl', align: 'center',minWidth:180}
       
          , {field: 'in_shelf', title: '<span lay-tips="上下架状态对已提取链接无效">是否上架</span>', align: 'center', templet: function (d) {
              if (d.novel.in_shelf === 0) {
                return '<span style="color: #FF5722;">绝对下架</span>';
              } else if (d.novel.in_shelf === 2) {
                return '<span style="color: #FF5722;">下架</span>';
              }else {
                return '上架';
              }
            }}
          , {title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-useradmin-admin'}
        ]]
      });

      //头工具栏事件
      table.on('toolbar(LAY-user-back-role)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
          case 'add':
            $("#quick_id").val('');
            $("#novel_ids").val('');
            form.render('select');
            layer.open({
              type: 1,
              title:'添加审核书籍',
              offset: '15px',
              skin: 'layui-layer-demo',
              area: ['35%', '350px'],
              closeBtn: 0, //不显示关闭按钮
              anim: 2,
              shadeClose: true, //开启遮罩关闭
              content: $('.man-show'),
              btn: ['确定', '取消']
              ,yes: function(index, layero){
                var novel_ids = $("#novel_ids").val();
                let replacedText = novel_ids.replace(/，/g, ',');
                $("#novel_ids").val(replacedText);
                var quickId = $("#quick_id").val();
                admin.req({
                  url: '/quick_app/addExamineNovel'
                  , type: "POST"
                  ,
                  data: {'novel_ids': novel_ids, 'quick_id': quickId}
                  , done: function (res) {
                    layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                      layer.close(index); //关闭弹层
                      table.reload('LAY-user-back-role');
                    });
                  },not_finish:function (res) {
                    layer.msg(res.msg);
                  }
                });
              }
            });
            break;
          case 'del':
            var data = checkStatus.data;
            if (data.length === 0) {
              layer.msg('请选择需要删除的书籍');
              return false;
            }
            var ids = [];
            for (var key in data) {
              ids.push(data[key]['id']);
            }
            layer.confirm('确定批量删除这些书籍吗？',{title: false}, function(index){
              admin.req({
                url: '/quick_app/delExamineNovel'
                , type: "POST"
                , data: {'ids': ids}
                , done: function (res) {
                  layer.msg('删除成功', {icon: 1, time: 1000}, function () {
                    layer.closeAll();
                    table.reload('LAY-user-back-role');
                  });
                }, not_finish: function (res) {
                  layer.msg(res.msg);
                }
              });
            });
            break;
        }
      });




      //监听工具条
      table.on('tool(LAY-user-back-role)', function(obj){
        var data = obj.data;
        if (obj.event === 'del'){
          layer.confirm('确认删除《'+obj.data.novel.title+'》审核书吗', {icon: 3, title:false}, function(index){
            admin.req({
              url: '/quick_app/delExamineNovel'
              , type: "POST"
              , data: {'ids': [obj.data.id]}
              , done: function (res) {
                layer.msg('删除成功', {icon: 1, time: 1000}, function () {
                  obj.del();
                  layer.close(index);
                });
              },not_finish:function (res) {
                layer.msg(res.msg);
              }
            });
          });
        }
      });

    });
  </script>
  <script>
    function random() {
      layui.admin.req({
        url: '/quick_app/getRandomExamineNovels'
        , type: "POST"
        ,
        data: {}
        , done: function (res) {
          var val = layui.$("#novel_ids").val();
          if (val){
            // 使用正则表达式匹配逗号
            var regex = /[,，]$/;
            if (regex.test(val)) {
              val = val + res.data;
            } else {
              val = val + ',' + res.data;
            }
          }else {
            val = res.data;
          }
          layui.$("#novel_ids").val(val);
        },not_finish:function (res) {
          layer.msg(res.msg);
        }
      });
    }
  </script>
</body>